package pecs210801;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class TestPECS {
    public static void main(String[] args) {
        // java: 不兼容的类型: java.util.ArrayList<pecs.Apple>无法转换为java.util.List<pecs.Fruit>

        // 1.
//        Fruit apple = new Apple();
//        List<Fruit> plate = new ArrayList<Apple>();

        // 2. 上界：只能取不能存
//         List<? extends Fruit> plate = new ArrayList<Apple>();

//        List<Apple> appleList = new ArrayList<>();
//        appleList.add(new Apple());
//        List<? extends Fruit> plate = appleList;
//        Fruit fruit = plate.get(0);

        // 不能存
//        plate.add(new Apple());
        // 不让存的原因
//        List<? extends Fruit> plate = new ArrayList<Apple>();
//        plate.add(new Banana());

        // 介绍下界
        List<? super Apple> plate = new ArrayList<>();

//        plate.add(new Apple());
//        plate.add(new RedApple());
//        plate.add(new GreenApple());
//
//        plate.add(new Fruit());
//        plate.add(new Banana());
//        Object object = plate.get(0);
//        Object object1 = plate.get(1);

        // 既然我们知道了解决的是最上方的问题，那么这里加上泛型上下界的实际用法
        MyStack<Fruit> myStack = new MyStack<>();

        List<Apple> appleList = new ArrayList<>();
        appleList.add(new Apple());
        appleList.add(new Apple());

        myStack.pushAll(appleList);

        List<Food> testPopAll = new ArrayList<>();
        myStack.popAll(testPopAll);
    }
}
